﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DAO
{
    public class PaymentDao
    {
        public PaymentDao()
        {
            SqlHelper sql = new SqlHelper();
        }
        public bool insertPayment(string reason, string receivePerson, string notes, DateTime paydate, float total, int user)
        {
            return SqlHelper.ExecuteNonQuery("INSERT_PAYMENT", CommandType.StoredProcedure,
                "@REASON", reason,
                "@PERSON_RECEIVE", receivePerson,
                "@NOTES", notes,
                "@CREATE_AT", paydate,
                "@TOTAL", total,
                "@CREATE_BY", user);
        }

        public DataTable getPayments(DateTime fromDate, DateTime toDate)
        {
            return SqlHelper.ExecuteDataTable("GET_PAYMENTS", CommandType.StoredProcedure,
                "@DATE_FORM", fromDate,
                "@DATE_TO", toDate);
        }

        public DataRow getTotalPayment(DateTime fromDate, DateTime toDate)
        {
            DataTable table = SqlHelper.ExecuteDataTable("GET_TOTAL_PAY", CommandType.StoredProcedure,
                "@DATE_FORM", fromDate,
                "@DATE_TO", toDate);
            if (table != null && table.Rows.Count >0)
            {
                return table.Rows[0];
            }
            return null;
        }
        public DataTable getGetAndPayment(DateTime fromDate, DateTime toDate)
        {
            return SqlHelper.ExecuteDataTable("GET_THU_CHI", CommandType.StoredProcedure,
                "@DATE_FORM", fromDate,
                "@DATE_TO", toDate);
        }

        public DataRow getTotalGetAndPayment(DateTime fromDate, DateTime toDate)
        {
            DataTable table = SqlHelper.ExecuteDataTable("GET_GET_PAY_TOTAL", CommandType.StoredProcedure,
                "@DATE_FORM", fromDate,
                "@DATE_TO", toDate);
            if (table != null && table.Rows.Count > 0)
            {
                return table.Rows[0];
            }
            return null;
        }

        public bool cancelPayments(int id)
        {
            return SqlHelper.ExecuteNonQuery("CANCEL_PAYMENTS", CommandType.StoredProcedure,
                "@ID", id);
        }

    }
}
